Skip to content

Get rid of github.com/go-chi/render use#1919

Merged
umputun merged 1 commit intomasterfrom
paskal/chi_render
Dec 3, 2025
Merged

Get rid of github.com/go-chi/render use#1919
umputun merged 1 commit intomasterfrom
paskal/chi_render

Conversation

@paskal
Copy link
Copy Markdown
Collaborator

@paskal paskal commented Mar 31, 2025

Replace go-chi/render with go-pkgz/rest for JSON responses and custom
helpers for HTML/plain text responses.

Key changes:

  • Replace render.JSON/render.Status with rest.RenderJSON and explicit
    w.WriteHeader() calls
  • Replace render.DecodeJSON with json.NewDecoder().Decode()
  • Add SendErrorJSON helper that sets Content-Type header before
    WriteHeader (required since rest.RenderJSON can't set headers after
    WriteHeader is called)
  • Add HTMLResponse and PlainTextResponse helpers

Fix export double-execution in migrator.go:
The original code called Export twice - once to io.Discard to check for
errors, then again to actually write. This was wasteful and had a race
condition risk. Now file mode buffers to memory first for atomic
success/failure, while stream mode writes directly with proper error
handling.

@paskal paskal added the backend label Mar 31, 2025
@paskal paskal requested review from Copilot and umputun March 31, 2025 18:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request removes the dependency on github.com/go-chi/render by replacing its usage with direct response writing and a custom WriteJSON helper, thereby standardizing the response handling across backend REST endpoints.

  • Replaced all render.HTML, render.JSON, and render.Status calls with w.WriteHeader, w.Write, and rest.WriteJSON.
  • Updated JSON decoding in tests and controllers to use encoding/json instead of render.DecodeJSON.
  • Removed the go-chi/render import from multiple files.

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
backend/app/rest/httperrors.go Removed render calls; added the WriteJSON helper function.
backend/app/rest/api/rest_public.go Replaced render methods with rest.WriteJSON and json.Decoder.
backend/app/rest/api/rest_private_test.go Updated tests to use json.Unmarshal instead of render.DecodeJSON.
backend/app/rest/api/rest_private.go Replaced render calls with rest.WriteJSON in various controllers.
backend/app/rest/api/rest.go Replaced render calls with rest.WriteJSON.
backend/app/rest/api/migrator.go Replaced render calls with rest.WriteJSON for import endpoints.
backend/app/rest/api/admin.go Replaced render calls with rest.WriteJSON in admin handlers.
Files not reviewed (1)
  • backend/go.mod: Language not supported
Comments suppressed due to low confidence (1)

backend/app/rest/api/admin.go:200

  • [nitpick] The JSON key 'read-only' uses a hyphen; consider using camelCase (e.g., 'readOnly') for better consistency and to avoid potential client parsing issues.
rest.WriteJSON(w, http.StatusOK, R.JSON{"locator": locator, "read-only": roStatus})

@paskal paskal force-pushed the paskal/chi_render branch from 8605920 to 93cdd50 Compare March 31, 2025 19:10
@paskal paskal requested a review from Copilot March 31, 2025 19:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the dependency on github.com/go-chi/render and replaces its usage with custom response writers. Key changes include:

  • Removing go-chi/render from imports and replacing its methods with rest.WriteJSON and explicit response writes.
  • Modifying controllers and tests to use standard json encoding/decoding.
  • Updating error and HTML response handling to ensure proper headers and status codes.

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
backend/app/rest/httperrors.go Replaces go-chi/render with custom WriteJSON and explicit HTML response handling
backend/app/rest/api/rest_public.go Removes go-chi/render usage; updates JSON and plain text response logic
backend/app/rest/api/rest_private_test.go Adjusts tests to use json.Unmarshal instead of render.DecodeJSON
backend/app/rest/api/rest_private.go Updates multiple endpoints to use WriteJSON and explicit header/status writing
backend/app/rest/api/rest.go Removes go-chi/render, using WriteJSON for consistent JSON responses
backend/app/rest/api/migrator.go Replaces go-chi/render with WriteJSON in import and wait endpoints
backend/app/rest/api/admin.go Updates admin endpoints to use WriteJSON instead of go-chi/render
Files not reviewed (1)
  • backend/go.mod: Language not supported
Comments suppressed due to low confidence (1)

backend/app/rest/api/admin.go:200

  • [nitpick] The JSON key 'read-only' may be unclear or inconsistent with common naming conventions; consider renaming it to 'readonly' for consistency and clarity.
rest.WriteJSON(w, http.StatusOK, R.JSON{"locator": locator, "read-only": roStatus})

@paskal paskal marked this pull request as draft March 31, 2025 19:15
@paskal paskal force-pushed the paskal/chi_render branch from 93cdd50 to a8d5964 Compare April 5, 2025 02:09
@paskal paskal force-pushed the paskal/chi_render branch from a8d5964 to d2ddedd Compare December 3, 2025 12:17
Replace go-chi/render with go-pkgz/rest for JSON responses and custom
helpers for HTML/plain text responses.

Key changes:
- Replace render.JSON/render.Status with rest.RenderJSON and explicit
  w.WriteHeader() calls
- Replace render.DecodeJSON with json.NewDecoder().Decode()
- Add SendErrorJSON helper that sets Content-Type header before
  WriteHeader (required since rest.RenderJSON can't set headers after
  WriteHeader is called)
- Add HTMLResponse and PlainTextResponse helpers

Fix export double-execution in migrator.go:
The original code called Export twice - once to io.Discard to check for
errors, then again to actually write. This was wasteful and had a race
condition risk. Now file mode buffers to memory first for atomic
success/failure, while stream mode writes directly with proper error
handling.
@paskal paskal force-pushed the paskal/chi_render branch from d2ddedd to dedac80 Compare December 3, 2025 13:17
@paskal paskal marked this pull request as ready for review December 3, 2025 13:21
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 19895196749

Details

  • 70 of 79 (88.61%) changed or added relevant lines in 6 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.1%) to 84.386%

Changes Missing Coverage Covered Lines Changed/Added Lines %
backend/app/rest/httperrors.go 12 16 75.0%
backend/app/rest/api/migrator.go 21 26 80.77%
Files with Coverage Reduction New Missed Lines %
backend/app/rest/httperrors.go 1 87.27%
backend/app/rest/api/migrator.go 2 70.83%
Totals Coverage Status
Change from base Build 19017599478: -0.1%
Covered Lines: 6053
Relevant Lines: 7173

💛 - Coveralls

Copy link
Copy Markdown
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - clean removal of go-chi/render dependency with proper replacement using go-pkgz/rest

@umputun umputun merged commit baf0db1 into master Dec 3, 2025
3 checks passed
@umputun umputun deleted the paskal/chi_render branch December 3, 2025 17:41
@paskal paskal added this to the v1.15.0 milestone Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants